// 引入二次封装的axios
import request from '@utils/request'

// 请求商品分类
const fetchCates = (params = {}) => request.get('/shop/goods/category/all', {
  params
})
// 首页轮播
const fetchHomeBanner = (params = {}) => request.get('/banner/list', {
  params
})
// 请求商品列表
const fetchItems = (params = {}) => request.post('/shop/goods/list/v2', params) // 第二个params指的是实参，前面的params是形参，形参接收到传来的实参参数，然后把第二个params return出去，获取到参数
// 请求商品详情
const fetchItemDetail = (id) => request.get('/shop/goods/detail', {
  params: {
    id
  }
}) // 第二个params指的是实参，前面的params是形参，形参接收到传来的实参参数，然后把第二个params return出去，获取到参数
// 加入购物车
const addCart = (params = {}) => request.post('/shopping-cart/add', params)
// 用户注册
const register = (params = {}) => request.post('/user/username/register', params)
// 用户登录
const doLogin = (params = {}) => request.post('/user/username/login', params)
// 读取购物车数据
const getCartInfo = (params = {}) => request.get('/shopping-cart/info', {
  params
})
// 修改购物车商品购买数量
const setCartNum = (params = {}) => request.post('/shopping-cart/modifyNumber', params)
// 删除购物车中的商品
const delCateItem = (params = {}) => request.post('/shopping-cart/remove', params)
// 修改购物车商品中的选中状态
const setItemSelected = (params = {}) => request.post('/shopping-cart/select', params)
// 添加收货联系人
const addContact = (params = {}) => request.post('/user/shipping-address/add', params)
// 联系人列表
const contactLists = (params = {}) => request.post('/user/shipping-address/list/v2', params)
// 编辑联系人
const contactUpdate = (params = {}) => request.post('/user/shipping-address/update', params)
// 获取收货人的详情
const fetchContactInfo = (params = {}) => request.get('/user/shipping-address/detail/v2', {
  params
})
// 删除联系人
const deleteContact = (params = {}) => request.post('/user/shipping-address/delete', params)
// 获取默认联系人
const fetchDefault = (params = {}) => request.get('/user/shipping-address/default/v2', {
  params
})

export {
  fetchCates,
  fetchHomeBanner,
  fetchItems,
  fetchItemDetail,
  addCart,
  register,
  doLogin,
  getCartInfo,
  setCartNum,
  delCateItem,
  setItemSelected,
  addContact,
  contactLists,
  contactUpdate,
  fetchContactInfo,
  deleteContact,
  fetchDefault
}
